﻿#region Using

using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;

using Common.Base;

using GameLogic.External;

#endregion

namespace CommunicationLibrary.TransportData
{
    [DataContract(Name = "E", IsReference = true)]
    public class Tile
    {
        public Tile(ITile tile)
        {
            this.Building = InstanceManager.Instance.GetOrAddBuilding(tile.Building);
            this.Hitpoints = tile.Hitpoints;
            this.Position = tile.Position;
            this.Identifier = tile.Identifier;

            this.Owner = InstanceManager.Instance.GetOrAddPlayer(tile.Owner);
            this.FarmerRoutes = tile.FarmerRoutes.Select(InstanceManager.Instance.GetOrAddRoute);
            this.MilitiaRoutes = tile.MilitiaRoutes.Select(InstanceManager.Instance.GetOrAddRoute);
        }

        [DataMember(Name = "A")]
        public int Identifier { get; private set; }

        [DataMember(Name = "B")]
        public Player Owner { get; private set; }

        [DataMember(Name = "C")]
        public Building Building { get; private set; }

        [DataMember(Name = "D")]
        public IEnumerable<Route> FarmerRoutes { get; private set; }

        [DataMember(Name = "E")]
        public IEnumerable<Route> MilitiaRoutes { get; private set; }

        [DataMember(Name = "F")]
        public int Hitpoints { get; private set; }

        [DataMember(Name = "G")]
        public Position Position { get; private set; }
    }
}